home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 27 / Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64 / iv owen < prev    next >
Text File  |  2023-02-26  |  18KB  |  615 lines

  1. ..
  2.  
  3.      Interview with Simon Owen
  4.      Sinclair Spectrum Vic 20
  5.           emulator creator
  6.  
  7. http://simonowen.com/
  8.  spectrum/vic20emu/
  9.  
  10. COMMODORE FREE
  11. Please introduce yourself to our
  12. readers
  13.  
  14. SIMON OWEN
  15. I'm Simon Owen from Nottingham in the
  16. UK. I'm 36 & work as a software
  17. developer, writing mainly Windows
  18. software for multi-function
  19. (fax/print/scan) devices. In my spare
  20. time I work on a variety of retro-
  21. themed coding projects. Most of them
  22. involve the Spectrum, SAM Coupe or
  23. floppy disks, but I'll dabble in a
  24. bit of anything I find interesting.
  25.  
  26. CF. Can you tell our readers a little
  27. about your first computing moments?
  28.  
  29. SO. I wrote my very first (BASIC)
  30. program on a computer my Dad borrowed
  31. from work, which was a large beige
  32. machine with green screen display &
  33. twin 8" floppy drives. My first
  34. proper home computer was a Jupiter
  35. Ace, back at the time when many
  36. people had VIC-20s or ZX81s. The Ace
  37. used Forth rather than BASIC as its
  38. built-in language, which was a bit
  39. mind-bending for me as a 10 year old!
  40.  
  41. I finally joined the mainstream a
  42. couple of years later, with a 48K
  43. Spectrum+. It was largely used for
  44. playing games, but after getting
  45. Hisoft DevPac for a birthday present
  46. I spent more & more time programming.
  47. From there I moved to the Spectrum
  48. 128+ in 1986, & the SAM Coupe when it
  49. was released in 1989.
  50.  
  51. CF. Are you a C= user?
  52.  
  53. SO. Only on the 16-bit side, really
  54. I've got A500 & A1200 machines. The
  55. A500 was originally so I could work
  56. on Uni projects at home, but I soon
  57. got sucked into demos & gaming. The
  58. A1200 is still very much alive today,
  59. thanks to an accelerator board &
  60. bootable Compact Flash card.
  61.  
  62. I'd still very much like a C64,
  63. though I'm not sure I could go back
  64. to loading from tapes. I'll
  65. definitely get one if I can find a
  66. ready-made CF or Ethernet solution
  67. for loading software. I'm aware of
  68. the IDE64 project, but like most
  69. retro hardware projects it expects
  70. everyone to assemble their own, &
  71. unfortunately I'm a fire hazard with
  72. a soldering iron!
  73.  
  74. I also have a SID interface board for
  75. my SAM Coupe, as I'm a fan of C64
  76. music. The 6502 core used by the VIC
  77. emulator was actually written for my
  78. SAM HardSID player, which can play
  79. most SID tunes through the SID board.
  80.  
  81. CF. Why design a VIC-20 emulator for
  82. the ZX Spectrum?  Are you stuck for
  83. things to do?
  84.  
  85. SO. Mainly because I like a technical
  86. challenge! I never really pay too
  87. much attention to how useful the
  88. final program will be, & if just one
  89. other person appreciates what's been
  90. achieved then I'm happy. The VIC-20
  91. emulator is my third 6502-based
  92. emulator, after Orao & Apple 1. It
  93. was definitely a step up in
  94. difficulty, but the hardware
  95. requirements didn't seem too extreme
  96. to be worth a go.
  97.  
  98. CF. The speed of the emulation must
  99. have been a problem.  Were there any
  100. specific tricks you had to use to
  101. obtain better performance?
  102.  
  103. SO. I try not to worry too much about
  104. the final running speed, as I know a
  105. standard Spectrum will never reach
  106. 100%. Even so, the 6502 core has been
  107. highly optimised over the years, & I
  108. feel there's little room for further
  109. gains.
  110.  
  111. The emulator does use a few tricks to
  112. maximise performance. The version of
  113. the 6502 core used by the VIC
  114. emulator traps only memory writes, so
  115. reads are fast & direct. To support
  116. I/O reads from devices such as the
  117. keyboard, the write handlers prepare
  118. the memory state for the reads. For
  119. the keyboard that means writes to the
  120. row selection at $9120 will prepare
  121. the keyboard state result at
  122. $9121/$912f.
  123.  
  124. Another optimisation is to use a
  125. large look-up table to map from VIC
  126. to Spectrum display addresses, to
  127. minimise the calculations during
  128. display writes. This table must be
  129. rebuilt if the number of VIC
  130. rows/columns changes, but that
  131. doesn't happen very often so it's
  132. still well worthwhile.
  133.  
  134. Perhaps the biggest outstanding
  135. performance issue is the VIC ROM
  136. keyboard scanning performed by the
  137. interrupt handler. If a quick test
  138. shows that no key is pressed the
  139. scanner exits early. Otherwise it
  140. continues to perform a full keyboard
  141. matrix scan, which eats a significant
  142. portion of the CPU time each frame as
  143. long as a key remains pressed. That's
  144. a problem for games that use keys
  145. instead of joystick for control.
  146.  
  147. CF. I know the Spectrum had a faster
  148. processor than the VIC but the
  149. graphics & sound must have caused
  150. problems when writing the emulator?
  151.  
  152. SO. The VIC high-resolution mode
  153. actually maps through fairly well,
  154. with the Spectrum using a similar
  155. attribute system for each character.
  156. The Spectrum 128 sound chip
  157. (AY-3-8912) supports 3 tone channels
  158. plus a noise channel, which also
  159. matched the VIC capabilities.
  160. Unfortunately, the output from the AY
  161. noise generator is very limited, so
  162. the roaring firing noise in
  163. GridRunner becomes an irritating
  164. background hiss on the Spectrum
  165. version.
  166.  
  167. On the issue of processor speed, the
  168. Z80 typically requires more CPU
  169. cycles to do the same work, so the
  170. speed is much closer than you'd
  171. imagine. A simple example is LDA #0
  172. (2 cycles @1MHz) & LD A,0 (7 cycles
  173. @3.5MHz), which both take around the
  174. same amount of real time to execute.
  175.  
  176. You can see bigger differences if you
  177. look at the strengths of each
  178. processor. The fastest Z80
  179. instruction (4 cycles) is twice as
  180. fast on the Spectrum (3.5Hz) as the
  181. fastest 6502 instruction (2 cycles)
  182. on the VIC (1MHz). There are more
  183. general purpose Z80 registers, which
  184. provide faster working space than
  185. main memory. The 16-bit register
  186. pairs also give easy access to any
  187. location in the 64K address space, as
  188. well as 16-bit arithmetic.
  189.  
  190. On the other hand, a typical 6502
  191. program averages around 2.5 cycles
  192. per instruction, which is only just
  193. above the minimum instruction time of
  194. 2 cycles. I also found that many
  195. tasks typically require fewer 6502
  196. instructions compared to the Z80.
  197. Zero page addressing also more than
  198. makes up for the lack of working
  199. registers too, & you're less likely
  200. to run out of them even with the most
  201. complex tasks.
  202.  
  203. CF. Colour clashing on the Spectrum
  204. was a problem.  Has this caused
  205. issues with emulation?
  206.  
  207. SO. The VIC's high-resolution mode is
  208. very similar to the Spectrum display,
  209. so it wasn't really a problem. In
  210. both cases each 8x8 pixel block has a
  211. foreground & a background colour. The
  212. VIC background colour is system-wide,
  213. with 4 bits selecting from the
  214. complete palette of 16 colours. 3
  215. bits from the colour RAM select one
  216. of 8 foreground colours for the 8x8
  217. block. On the Spectrum each block has
  218. a separate foreground & background
  219. colour (3 bits for each), as well as
  220. bright & flash bits. The bright bit
  221. increase the intensity of both
  222. foreground & background colours.
  223.  
  224. The emulator uses a table to map from
  225. VIC to Spectrum colours; since not
  226. all colours are available (orange is
  227. crudely mapped to yellow). Since the
  228. upper half of the VIC colours are
  229. roughly bright versions of the lower
  230. ones, bit 3 of the VIC background
  231. colour is mapped to the Spectrum
  232. bright bit. That does mean the
  233. foreground becomes bright too, but
  234. that doesn't make much difference
  235. overall.
  236.  
  237. CF. Writing an emulator where do you
  238. start?  I presume there must have
  239. been a lot of reading & internet
  240. trawling for specifications about the
  241. Vic's hardware?
  242.  
  243. SO. I'd done a little research before
  244. I started, just to make sure it was
  245. vaguely possible. I generally check
  246. that there is enough room for my
  247. emulator code in the same address
  248. space, which requires around 4K for
  249. the base 6502 emulator or 8K with a
  250. faster instruction decode table. Next
  251. is to make sure the display can be
  252. suitably represented, even if some
  253. features are missing. I also check
  254. for any custom hardware that might be
  255. needed to run typical programs.
  256.  
  257. I'd already written the 6502
  258. emulator, so it didn't take long to
  259. make some real progress. It only took
  260. about an hour to place the VIC ROM
  261. code at the appropriate memory
  262. locations & have it boot to the
  263. start-up screen. The only special
  264. code I needed was to stop the VIC
  265. memory test overwriting the CHARGEN
  266. ROM at $8000. Once I made that
  267. location appear as ROM, it finished
  268. the RAM test & set RAMTOP, & then
  269. continued to boot. At that point
  270. there was nothing to see on the
  271. screen, but peeking the VIC display
  272. memory locations I could see it was
  273. showing the number of free bytes. A
  274. small addition to trap writes to
  275. $900F also gave the expected cyan
  276. border.
  277.  
  278. CF. I don't want to get into the my
  279. computer was better than yours as our
  280. readers will mainly be C= users,
  281. although I do know of some Spectrum
  282. readers.  There is still a rivalry
  283. between machines why do you think
  284. this still exists?
  285.  
  286. SO. I think there will always be some
  287. rivalry, but (except for a few vocal
  288. individuals) it seems to be fairly
  289. light-hearted nowadays. Almost
  290. everyone I've spoken to seems to have
  291. at least some appreciation of the
  292. other machine. Perhaps not
  293. surprisingly, most people seem to
  294. prefer the one they grew up with.
  295. Would it surprise you to learn that
  296. in a World of Spectrum poll comparing
  297. the Spectrum 128K & C64 sound chips,
  298. 67% of votes were for the SID? :-)
  299.  
  300. CF. SAM Coupe! Some readers may not
  301. be familiar with this machine you
  302. also have a Vic emulator for this
  303. machine can you enlighten our readers
  304. about the machine?
  305.  
  306. SO. I see the SAM as a spiritual
  307. successor to the Spectrum, even
  308. though it's no direct relation. It
  309. features a 6MHz Z80B, 512K RAM (plus
  310. up to 4MB externally), 128 colours,
  311. high colour & hi-res modes, 6 channel
  312. sound, & up to 2 built-in floppy
  313. drives. SAM is backwards compatible
  314. with 48K Spectrum software, but only
  315. native titles make the most of the
  316. extra hardware, of course. The SAM
  317. versions of Lemmings & Prince of
  318. Persia stand up well against the
  319. Atari ST versions. Unfortunately,
  320. SAM's release in 1989 was at a time
  321. when 16-bit machines were starting to
  322. become popular. The user base was
  323. also too small for much big name
  324. commercial interest, instead relying
  325. on smaller companies, diskzines &
  326. home-grown software.
  327.  
  328. The SAM version of the VIC emulator
  329. makes use of extra hardware features.
  330. The faster processor gives a welcome
  331. boost to running speed, the original
  332. VIC colour palette is fully
  333. supported, & the SAA 1099 noise
  334. generator sounds much more authentic.
  335. With a Mayhem accelerator card for
  336. SAM running at 28MHz you can even
  337. have it running at original VIC
  338. speed!
  339.  
  340. CF. I know about 2 different spectrum
  341. models the 16 & 48k but I have heard
  342. there were other models, does this
  343. emulator run on all spectrums.  Can
  344. you enlighten us on a little spectrum
  345. history?
  346.  
  347. SO. The 16K & 48K versions were both
  348. released in 1982. The very earliest
  349. software ran on the 16K machines, but
  350. it wasn't long before 48K was the
  351. minimum requirement. Fortunately,
  352. there was a RAM add-on to boost 16K
  353. machines up to 48K. The vast majority
  354. of Spectrum titles were aimed at the
  355. 48K market. The Spectrum+ update in
  356. 1984 was little more than the
  357. original board in a new case, with a
  358. hard plastic keyboard replacing the
  359. rubber one.
  360.  
  361. The Spectrum 128K was released in
  362. 1986, featuring extra memory & a 3
  363. channel sound chip (AY-3-8912). Games
  364. used the improved sound for menu or
  365. background music, & additional in
  366. game sound effects. Only a handful of
  367. games were 128K only, with most just
  368. using the extra space for the music
  369. player, digitised speech, or
  370. pre-loading game levels.
  371.  
  372. After Amstrad took over the Spectrum
  373. 128 was repackaged in a CPC-like case
  374. with improved keyboard & built-in
  375. cassette recorder, & released as the
  376. Spectrum +2. The final release was
  377. the Spectrum +3, which replaced the
  378. cassette recorder with a 3" disk
  379. drive, as used by other Amstrad
  380. machines. To simplify production the
  381. later +2 machines (known as the +2A)
  382. used the same main boards as the +3,
  383. with boot-time detection of the disk
  384. drive to know how it should identify
  385. itself.
  386.  
  387. The VIC-20 emulator uses the extra
  388. capabilities of the +2A & +3 to page
  389. RAM into the full 64K address space,
  390. so no memory mapping is needed
  391. between VIC & Spectrum addressing.
  392. That does mean it won't run on the
  393. original 48K or even the base 128K
  394. model, but since most users will be
  395. using a Spectrum emulator it's not a
  396. problem.
  397.  
  398. There is a second VIC-20 emulator for
  399. the Spectrum, written by Jimmy. It
  400. uses his own 6502 core & does include
  401. the memory mapping needed to run on
  402. 48K machines. That does mean a speed
  403. penalty for each memory access, but
  404. the emulator does still run
  405. surprisingly well.
  406.  
  407. CF. How long did creating the
  408. emulator take?
  409.  
  410. SO. Start to finish was 18 months,
  411. but I only spent about 2-3 weeks of
  412. evenings actually working on it. The
  413. first evening was to confirm the ROMs
  414. booted, & to get a sample game cart
  415. booting. After that I left it alone
  416. to think about how best to emulate
  417. the display. I only picked it up
  418. again recently to finish it off.
  419.  
  420. I originally believed that changes to
  421. chargen RAM would be used by games
  422. for character animation. That would
  423. mean tracking the visible characters,
  424. to know which needed updating when
  425. the underlying character memory was
  426. changed. To do that would require
  427. multiple levels of tables, with a
  428. speed hit for all display writes.
  429. Before I'd got that straight in my
  430. head I'd moved on to other projects.
  431.  
  432. The final emulator is actually much
  433. simplified, ignoring the chargen
  434. memory writing that (it turns out)
  435. very few programs need. Display
  436. writes are still trapped, but the
  437. only work is to write the current
  438. character representation to the
  439. Spectrum display. The only
  440. complications are when the chargen
  441. pointer ($9005) or rows/columns
  442. ($9002-3) are changed, when the
  443. entire display must be redrawn.
  444.  
  445. CF. How many people are involved with
  446. creating the package?
  447.  
  448. SO. Just me for the coding, but I've
  449. had input from a number of people.
  450. Jimmy helped kick-start me into
  451. finishing the emulator, & various
  452. optimisation ideas we've discussed
  453. have benefitted both our emulators.
  454. Dr Beep also provided a great
  455. opcode-decode speed-up, where the
  456. opcode itself forms the low-byte of
  457. the handler address, for around a 5%
  458. speed boost.
  459.  
  460. CF. What comments from the Spectrum
  461. world have you had?
  462.  
  463. SO. Actually not very much, with more
  464. feedback from the C= world! Most of
  465. the Spectrum interest has been in the
  466. 6502 core, rather than the emulator
  467. itself. Perhaps the VIC-20 is a
  468. little too unknown to the average
  469. Spectrum user, compared to the C64.
  470.  
  471. CF. Do you have plans for a C64
  472. emulator for the Spectrum or SAM
  473. Coupe?  I guess speed would be a
  474. major stumbling block.
  475.  
  476. SO. The C64 would definitely be a lot
  477. more challenging. It would probably
  478. need the extra video capabilities of
  479. the SAM Coupe to support the colours
  480. & modes for games. The need for
  481. memory paging would mean moving from
  482. direct to slower mapped memory
  483. accesses, & trapping zero-page paging
  484. I/O would slow all zero-page writes a
  485. little. Graphic sprites would
  486. complicate the display updating too,
  487. requiring twice the amount of drawing
  488. when they're moved. I'm very tempted
  489. to look at supporting the C64 so that
  490. BASIC is usable & if that goes well
  491. then maybe I'll enhance it further.
  492.  
  493. CF. With the emulator not running at
  494. full speed are there any programs
  495. that just refuse to run?
  496.  
  497. SO. The running speed isn't a problem
  498. for most programs, as they're not
  499. aware of how fast they're running.
  500. Any awareness they have of elapsed
  501. time can be adjusted as part of the
  502. emulation, if required. The most
  503. likely reason for non-working
  504. programs will be incomplete
  505. emulation. For instance, I make no
  506. attempt to support the hardware
  507. timers or scan line counters, so
  508. anything relying on them will fail.
  509. It may be possible to add some basic
  510. support for them, but I've not needed
  511. them yet.
  512.  
  513. CF. How accurate is the emulation?
  514.  
  515. SO. The CPU emulation is quite
  516. accurate, supporting all the
  517. officially documented instructions.
  518. It's actually a 65C02 emulation,
  519. which includes some page-wrapping
  520. fixes & new instructions that were
  521. missing from the original 6502. The
  522. VIC chip is not fully emulated, but
  523. I've added enough support for the
  524. sample programs to run. The display
  525. is also narrower that the original
  526. machine, but I believe that's just
  527. the way the VIC display is generated,
  528. where the pixels are fatter.
  529.  
  530. CF. Do you intend to support C=
  531. hardware to attach to the spectrum,
  532. maybe a cartridge port?
  533.  
  534. SO. It's unlikely original carts will
  535. ever be supported directly as it
  536. would require special hardware to
  537. connect them to a Spectrum. I would
  538. still like to support dumps of game
  539. carts, as used by VICE & other
  540. emulators. Cart support isn't
  541. completely straight-forward either,
  542. as some will move the address of the
  543. VIC display, & the emulator is
  544. optimised for the normal addresses. 
  545. It also depends on the memory banks
  546. provided by the cart, as space is
  547. needed for the Spectrum display & the
  548. emulator itself.
  549.  
  550. CF. Did you consciously remove some
  551. VIC features so that the emulator
  552. would run faster or be quicker to
  553. produce?
  554.  
  555. SO. The biggest feature omission is
  556. the high-colour mode, which will be
  557. needed by most newer VIC-20 games.
  558. Not supporting it doesn't always make
  559. a big difference to appearance; it
  560. just shows with fewer colours. The
  561. flags in Blitzkrieg still look like
  562. flags, but they're missing the proper
  563. blue & white colouring. High-colour
  564. mode would only be possible with the
  565. SAM Coupe's 4-bit display mode. The
  566. change would also mean 4 times the
  567. amount of display data for any
  568. drawing, which would slow the
  569. emulator down a bit. I also cut the
  570. available memory from 24K in the
  571. original version to 3K in the
  572. released version.  Part of that was
  573. for software compatibility, but it
  574. was mainly to give more space for the
  575. Spectrum display & some look-up
  576. tables.  I should be able to provide
  577. at least 16K by moving a few things
  578. around, perhaps having the Spectrum
  579. display in a different memory bank.
  580.  
  581. CF. You have given the source code
  582. away, how would you feel about others
  583. altering & maybe tweaking the
  584. software?
  585.  
  586. SO. I'm quite happy for any or all of
  587. it to be used, if they credit me
  588. somewhere. That could mean using the
  589. 6502 core in a completely different
  590. project, or submitting improvements
  591. to the existing emulator.
  592.  
  593. CF. Do you have any other software;
  594. we better say C= related in the
  595. pipeline?
  596.  
  597. SO. Nothing currently, though new
  598. projects do have a habit of springing
  599. up from nowhere! There has been some
  600. recent discussion about a SID board
  601. for the Spectrum, for playing C64
  602. tunes during Spectrum games. It's
  603. certainly wacky enough for me to look
  604. at getting involved if it takes off.
  605.  
  606. CF. Well whatever your motives I
  607. think this is a major achievement & I
  608. have to take my hat of to you well
  609. done.
  610.  
  611. SO. Thank you for your interest & an
  612. interesting interview!
  613.  
  614. ..end..
  615.